export const columns1 = [{
  title: '商品编码',
  key: 'index'
}, {
  title: 'SKU编码',
  key: 'age'
}, {
  title: '商品',
  key: 'address'
}, {
  title: '零售价',
  key: 'name'
}, {
  title: '限购数量',
  key: 'name'
}, {
  title: '状态',
  key: 'discount'
}, {
  title: '库存',
  key: 'sale'
}, {
  title: '操作',
  key: 'price',
}]
export const columns2 = [{
  title: '商品编码',
  key: 'index'
}, {
  title: 'SKU编码',
  key: 'age'
}, {
  title: '商品',
  key: 'address'
}, {
  title: '零售价',
  key: 'name'
}, {
  title: '限购数量',
  key: 'name'
}, {
  title: '状态',
  key: 'discount'
}, {
  title: '库存',
  key: 'sale'
}, {
  title: '操作',
  key: 'price',
}]
export function setSelectList(data, val) {
  for (let item of data) {
    item.label = item[val.label]
    item.value = item[val.value]
  }
  return data;
}
export function setCascaderList(data, val) {
  for (let item of data) {
    item.label = item[val.mt][val.label]
    item.value = item[val.mt][val.value]
    item.children = item[val.child]
    if (item[val.child] && item[val.child].length) {
      setCascaderList(item[val.child], val)
    }
  }
}
const plusZero = (value) => {
  return value < 10 ? "0" + value : value;
}
export function formatDate(value, hasTime) {
  if (!value) return "";
  if (typeof value === 'string') {
    value = value.replace(/\-/g, "/");
  }
  value = new Date(value);
  let result = "";
  let year = value.getFullYear();
  let month = value.getMonth() + 1;
  let day = value.getDate();

  month = plusZero(month);
  day = plusZero(day);

  result = year + "-" + month + "-" + day;

  if (hasTime) {
    let hour = value.getHours();
    let minute = value.getMinutes();
    let seconds = value.getSeconds();
    hour = plusZero(hour);
    minute = plusZero(minute);
    seconds = plusZero(seconds)
    result += " " + hour + ":" + minute + ":" + seconds
  }

  return result;
}
export function getPuduct(data, val) {
  let newArray = [];
  // postParam:["productId","skuId","promotionPrice","isMustBuy"]
  // getParam:['productId','id','salePrice','isShelf']
  for (let item of data) {
    for (let todo of item[val.child]) {
      let param = {
        "productId": todo[val.getParam[0]],
        "skuId": todo[val.getParam[1]],
        "productSn": todo[val.getParam[4]],
        "promotionPrice": todo[val.getParam[3]],
        "skuSn": todo[val.getParam[2]]
      }
      if (val.getParam[5]) param[val.getParam[5]] = todo[val.getParam[5]]
      newArray.push(param)
    }
  }
  return newArray;
}
